home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / standards / sgml / nist / parse / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-13  |  7.2 KB  |  279 lines

  1. /* National Institute of Standards and Technology (NIST)
  2. /* National Computer System Laboratory (NCSL)
  3. /* Office Systems Engineering (OSE) Group
  4. /* ********************************************************************
  5. /*                            D I S C L A I M E R
  6. /*                              (March 8, 1989)
  7. /*  
  8. /* There is no warranty for the NIST NCSL OSE SGML parser and/or the NIST
  9. /* NCSL OSE SGML parser validation suite.  If the SGML parser and/or
  10. /* validation suite is modified by someone else and passed on, NIST wants
  11. /* the parser's recipients to know that what they have is not what NIST
  12. /* distributed, so that any problems introduced by others will not
  13. /* reflect on our reputation.
  14. /* 
  15. /* Policies
  16. /* 
  17. /* 1. Anyone may copy and distribute verbatim copies of the SGML source
  18. /* code as received in any medium.
  19. /* 
  20. /* 2. Anyone may modify your copy or copies of SGML parser source code or
  21. /* any portion of it, and copy and distribute such modifications provided
  22. /* that all modifications are clearly associated with the entity that
  23. /* performs the modifications.
  24. /* 
  25. /* NO WARRANTY
  26. /* ===========
  27. /* 
  28. /* NIST PROVIDES ABSOLUTELY NO WARRANTY.  THE SGML PARSER AND VALIDATION
  29. /* SUITE ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
  30. /* EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  31. /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  32. /* THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS
  33. /* WITH YOU.  SHOULD THE SGML PARSER OR VALIDATION SUITE PROVE DEFECTIVE,
  34. /* YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  35. /* 
  36. /* IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL NIST BE LIABLE FOR
  37. /* DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,
  38. /* INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  39. /* INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
  40. /* BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A
  41. /* FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY
  42. /* NIST) THE PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF
  43. /* SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  44. */
  45.  
  46. #include <stdio.h>
  47. #include <string.h>
  48. #include <ctype.h>
  49.  
  50.  
  51. int appflag = 0;
  52. char docname[128], pathname[128], entfilename[128], noption[128],
  53. foption[128], hoption[128], poption[128], coption[128], debug1[128],
  54. debug2[128], debug2a[128], debug3[128];
  55.  
  56. /*global*/  int main();
  57. /*global*/  void process();
  58. /*global*/  void error();
  59. /*global*/  void doparse1();
  60. /*global*/  void doparse1a();
  61. /*global*/  void doparse2a();
  62. /*global*/  void doparse2b();
  63. /*global*/  void doparse3();
  64. /*global*/  void showline();
  65.  
  66. /* =============================================================== */
  67. main(argc, argv)
  68. int argc;
  69. char *argv[];
  70. {
  71.    int j;
  72.    printf("\n\nNBS FIPS-SGML Reference Parser\n\n");
  73.    printf("Version 1.01\n");
  74.    fflush(stdout);
  75.    if (argc <= 1)
  76.       error("insufficient number of arguments");
  77.    for (j = 1; j < argc; j++)
  78.       process(argv[j]);
  79.    doparse1();
  80.    doparse1a();
  81.    doparse2a();
  82.    doparse2b();
  83.    doparse3();
  84. }
  85. /* =============================================================== */
  86. void process (arg)
  87. unsigned char *arg;
  88. {
  89.    unsigned char temp[128];
  90.    int infile, len;
  91.    /* if this is the document name */
  92.    if(*arg != '-') {
  93.       if ((infile = open(arg, 0)) == -1){
  94.          sprintf(temp, "unable to open document file:  %s", arg);
  95.          error(temp);
  96.       }
  97.       close(infile);
  98.       strcpy(docname, arg);
  99.       return;
  100.    }
  101.    arg++;
  102.    *arg = toupper(*arg);
  103.    switch(*arg) {
  104.    case 'S':
  105.       appflag = 1;
  106.       return;
  107.    case 'T':
  108.       strcpy(pathname, arg - 1);
  109.       len = strlen(pathname) - 1;
  110.       if (pathname[len] != '\\'){
  111.          pathname[len + 1] = '\\';
  112.          pathname[len + 2] = '\0';
  113.       }
  114.       return;
  115.    case 'P':
  116.       strcpy(entfilename, arg - 1);
  117.       return;
  118.    case 'N':
  119.       strcpy(noption, "-N");
  120.       return;
  121.    case 'F':
  122.       strcpy(foption, "-F");
  123.       return;
  124.    case 'H':
  125.       strcpy(hoption, "-H");
  126.       return;
  127.    case '1':
  128.       strcat(debug1, (arg - 1));
  129.       strcat(debug1, " ");
  130.       return;
  131.    case '2':
  132.       strcpy(debug2, (arg - 1));
  133.       return;
  134.    case 'A':
  135.       strcpy(debug2a, (arg - 1));
  136.       return;
  137.    case '3':
  138.       strcpy(debug3, (arg - 1));
  139.       return;
  140.    case 'X':
  141.       return;
  142.    default:
  143.       sprintf(temp, "illegal command line option:  %s", (arg - 1));
  144.       error(temp);
  145.    }
  146. }
  147. /* =============================================================== */
  148. void error(msg)
  149. unsigned char *msg;
  150. {
  151.    printf("%s\n",msg);
  152.    exit(1);
  153. }
  154. /* =============================================================== */
  155. void doparse1()
  156. {
  157.    char *arg[10];
  158.    int status;
  159.    arg[0] = "parse1";
  160.    arg[1] = docname;
  161.    /*arg[2] = pathname;*/
  162.    arg[2] = NULL;
  163.    arg[3] = entfilename;
  164.    arg[4] = debug1;
  165.    arg[5] = foption;
  166.    arg[6] = hoption;
  167.    arg[7] = poption;
  168.    arg[8] = NULL;
  169.    showline(arg);
  170.    if (fork() == 0) {
  171.       exit(execv("./parse1", arg));
  172.    }
  173.    wait(&status);
  174.    if (status != 0)
  175.       exit(1);
  176. }
  177. /* =============================================================== */
  178. void doparse1a()
  179. {
  180.    char *arg[10];
  181.    int status;
  182.    arg[0] = "parse1a";
  183.    arg[1] = pathname;
  184.    arg[2] = NULL;
  185.    showline(arg);
  186.    if (fork() == 0) {
  187.       exit(execv("./parse1a", arg));
  188.    }
  189.    wait(&status);
  190.    if (status != 0)
  191.       exit(1);
  192. }
  193.  
  194. /* =============================================================== */
  195. void doparse2a()
  196. {
  197.    char *arg[10];
  198.    int status;
  199.    arg[0] = "parse2a";
  200.    arg[1] = pathname;
  201.    arg[2] = debug2a;
  202.    arg[3] = foption;
  203.    arg[4] = hoption;
  204.    arg[5] = NULL;
  205.    showline(arg);
  206.    if (fork() == 0) {
  207.       exit(execv("./parse2a", arg));
  208.    }
  209.    wait(&status);
  210.    if (status != 0)
  211.       exit(1);
  212. }
  213. /* =============================================================== */
  214. void doparse2b()
  215. {
  216.    char *arg[10];
  217.    int status;
  218.    arg[0] = "parse2b";
  219.    arg[1] = pathname;
  220.    arg[2] = debug2a;
  221.    arg[3] = foption;
  222.    arg[4] = hoption;
  223.    arg[5] = NULL;
  224.    showline(arg);
  225.    if (fork() == 0) {
  226.       exit(execv("./parse2b", arg));
  227.    }
  228.    wait(&status);
  229.    if (status != 0)
  230.       exit(1);
  231. }
  232. /* =============================================================== */
  233. void doparse3()
  234. {
  235.    int status;
  236.    char *arg[10];
  237.    char temp[256], temp2[256];
  238.    int posfile, argindex = 0;
  239.    long pos;
  240.    strcpy(temp,pathname + 2);
  241.    strcat(temp,"posfile.sgm");
  242.    if ((posfile = open(temp,0)) == -1){
  243.       sprintf(temp2,"unable to open %s", temp);
  244.       error(temp2);
  245.    }
  246.    if (read(posfile, &pos, sizeof(pos)) != sizeof(pos)){
  247.       sprintf(temp2,"error in reading %s", temp);
  248.       error(temp2);
  249.    }
  250.    if(close(posfile) == -1){
  251.       sprintf(temp2,"error in closing %s", temp);
  252.       error(temp2);
  253.    }
  254.    unlink(temp);
  255.    arg[argindex++] = "parse3";
  256.    arg[argindex++] = docname;
  257.    sprintf(temp2, "-P%ld", pos);
  258.    arg[argindex++] = temp2;
  259.    arg[argindex] = NULL;
  260.    showline(arg);
  261.    if (fork() == 0) {
  262.       exit(execv("./parse3", arg));
  263.    }
  264.    wait(&status);
  265.    if (status != 0)
  266.       exit(1);
  267. }
  268. /* =============================================================== */
  269. void showline(arg)
  270. unsigned char *arg[];
  271. {
  272.    int j = 0;
  273.  
  274.    while (arg[j] != NULL)
  275.       printf("%s ",arg[j++]);
  276.    printf("\n");
  277. }
  278. /* =============================================================== */
  279.